Autonomic refresh of a materialized query table in a computer database

ABSTRACT

A method autonomically refreshes a materialized query table (MQT) in a computer database to improve database performance and utility. In preferred embodiments, the query optimizer autonomically initiates a refresh of MQT depending on an estimated time for the query to access the base tables. In other preferred embodiments, the query optimizer estimates the time for the query to access the base tables and compares it to the estimated time to refresh the MQT to determine whether to refresh the MQT and run the query over the MQT rather than the base tables.

CROSS-REFERENCE TO RELATED APPLICATION

This patent application is a continuation of U.S. Ser. No. 11/197,607filed on Aug. 4, 2005, which is incorporated herein by reference.

BACKGROUND OF THE INVENTION

1. Technical Field

This invention generally relates to computer database systems, and morespecifically relates to apparatus and methods for autonomic refresh of amaterialized query table in a computer database.

2. Background Art

Database systems have been developed that allow a computer to store alarge amount of information in a way that allows a user to search forand retrieve specific information in the database. Data is typicallystored in database tables. The tables contain columns and rows of data.The data in the table is related to or associated with other data incorresponding columns and rows. Relationships of the data are stored inindexes.

Retrieval of information from a database is typically done usingqueries. A database query typically includes one or more predicateexpressions interconnected with logical operators. The database issearched for records that satisfy the query, and those records arereturned as the query result. In database systems it is common foridentical or closely related queries to be issued frequently. When adatabase contains very large amounts of data, certain queries againstthe database can take an unacceptably long time to execute. The cost ofexecuting a query may be particularly significant when the queryrequires join operations among a large number of database tables.

It has become a common practice to store the results of often-repeatedqueries in database tables. By storing the results of queries, thecostly join operations required to generate the results do not have tobe performed every time the queries are issued. Rather, the databaseserver responds to the queries by simply retrieving the pre-stored data.These stored results are sometimes referred to as a materialized viewsor materialized query tables (MQT). The purpose for the MQT is toprovide an aggregation of data that can satisfy many subsequent querieswithout repeating the full access to the database.

As new data is periodically added to the base tables of a materializedquery table, the materialized query table needs to be updated to reflectthe new base table data. When a materialized query table accuratelyreflects all of the data currently in its base tables, the materializedquery table is considered to be “fresh”. Otherwise, the materializedquery table is considered to be “stale”. A stale materialized querytable may be re-computed by various techniques that are collectivelyreferred to as a “refresh”. Some prior art systems use different modesto tolerate data staleness. For example, software may access the MQT inEnforced mode, Trusted mode, or Stale-Tolerated mode. When softwareaccesses the data in Enforced mode, the data is required to be 100%accurate. If the MQT is not up to date when accessed in this mode, thedata must be retrieved from the base tables rather than from the MQT.Retrieving the data from the base tables is more costly in systemresources and in some cases may actually be more costly than updatingthe MQTs.

Without a way to update an MQT in an efficient manner, the computerindustry will continue to suffer from inefficiency and poor databaseperformance.

DISCLOSURE OF INVENTION

In accordance with the preferred embodiments, an apparatus and methodprovide autonomic refresh of an MQT in a computer database to improvedatabase performance and utility. In preferred embodiments, the queryoptimizer autonomically initiates a refresh of an MQT depending on anestimated time for the query to access the base tables. In otherpreferred embodiments, the query optimizer estimates the time for thequery to access the base tables and compares it to the estimated time torefresh the MQT to determine whether to refresh the MQT and run thequery over the MQT rather than run the query over the base tables.

The foregoing and other features and advantages of the invention will beapparent from the following more particular description of preferredembodiments of the invention, as illustrated in the accompanyingdrawings.

BRIEF DESCRIPTION OF DRAWINGS

The preferred embodiments of the present invention will hereinafter bedescribed in conjunction with the appended drawings, where likedesignations denote like elements, and:

FIG. 1 is an apparatus in accordance with the preferred embodiments;

FIG. 2 is a table showing expressions that may be included in apredicate expression in a database query;

FIG. 3 is a sample database query in Structured Query Language (SQL);

FIG. 4 is a predicate expression that is representative of the WHEREclause in the sample database query of FIG. 3;

FIG. 5 is an example flow diagram according to preferred embodiments;

FIG. 6 is an example flow diagram according to preferred embodiments;

FIG. 7 is an example flow diagram according to preferred embodiments;

FIG. 8 is another flow diagram illustrating a method according to thepreferred embodiments; and

FIG. 9 shows an example of historical data that is maintained by thequery optimizer according to preferred embodiments.

BEST MODE FOR CARRYING OUT THE INVENTION

1.0 Overview

The present invention relates to an apparatus and method to provideautonomic refresh of an MQT in a computer database to improve databaseperformance and utility. For those not familiar with databases orqueries, this Overview section provides background information that willhelp to understand the present invention.

Known Databases and Database Queries

There are many different types of databases known in the art. The mostcommon is known as a relational database (RDB), which organizes data intables that have rows that represent individual entries or records inthe database, and columns that define what is stored in each entry orrecord.

In a broader view, data in a database system is stored in one or moredata containers, where each container contains records, and the datawithin each record is organized into one or more fields. In relationaldatabase systems, the data containers are referred to as tables, therecords are referred to as rows, and the fields are referred to ascolumns as described above. In object oriented databases, the datacontainers are referred to as object classes, the records are referredto as objects, and the fields are referred to as attributes. Otherdatabase architectures may use other terminology. While not intended tobe limiting to relational databases, for the purpose of explanation, theexamples and the terminology used herein shall be that typicallyassociated with relational databases. Thus, the terms “table”, “row” and“column” shall be used herein to refer respectively to the datacontainer, record, and field and similarly apply to the other types ofdatabase containers. Retrieval of information from a database istypically done using queries. A database query is an expression that isevaluated by a database manager. The expression may contain one or morepredicate expressions that are used to retrieve data from a database.For example, let's assume there is a database for a company thatincludes a table of employees, with columns in the table that representthe employee's name, address, phone number, gender, and salary. Withdata stored in this format, a query could be formulated that wouldretrieve the records for all female employees that have a salary greaterthan $40,000. Similarly, a query could be formulated that would retrievethe records for all employees that have a particular area code ortelephone prefix.

A database query typically includes one or more predicate expressionsinterconnected with logical operators. A predicate expression is ageneral term given to an expression using one of the four kinds ofoperators (or their combinations): logical, relational, unary, andboolean, as shown in FIG. 2. A query usually specifies conditions thatapply to one or more columns of the database, and may specify relativelycomplex logical operations on multiple columns. The database is searchedfor records that satisfy the query, and those records are returned asthe query result.

One popular way to define a query uses Structured Query Language (SQL).SQL defines a syntax for generating and processing queries that isindependent of the actual structure and format of the database. Onesample SQL query is shown in FIG. 3. The SELECT statement tells thedatabase query processor to SELECT all columns, the A from Table1”clause identifies which database table to search, and the WHERE clausespecifies one or more expressions that must be satisfied for a record tobe retrieved. Note that the query of FIG. 3 is expressed in terms ofcolumns C1, C2 and C3. Information about the internal storage of thedata is not required as long as the query is written in terms ofexpressions that relate to values in columns from tables.

For the query of FIG. 3, the WHERE clause specifies that the firstcolumn has a value equal to four (C1=4) logically ANDed with theexpression that the second column is greater than six OR the thirdcolumn is not equal to eight. The expression in the WHERE clause of FIG.3 is shown in FIG. 4. Where not specifically stated herein, the term“expression” is intended to mean an arbitrary predicate expression,which can be an entire expression in a query, a portion of an expressionin a query, or the entire query and may include logical expressions,relational expressions, unary expressions, boolean expressions, andtheir combinations.

In database systems it is common for identical or closely relatedqueries to be issued frequently. To respond to such queries, thedatabase server typically has to perform numerous join operationsbecause the database records contain the information that is required torespond to the queries. When a database contains very large amounts ofdata, certain queries against the database can take an unacceptably longtime to execute. The cost of executing a query may be particularlysignificant when the query (which takes the form of a “SELECT” statementin the SQL database language) requires join operations among a largenumber of database tables.

Materialized Query Tables

It has become a common practice to store the results of often-repeatedqueries in database tables or some other persistent database object. Bystoring the results of queries, the costly join operations required togenerate the results do not have to be performed every time the queriesare issued. Rather, the database server responds to the queries bysimply retrieving the pre-stored data. These stored results aresometimes referred to as materialized views or materialized query tables(MQT). An MQT initially may be a computed result of a given query. Thepurpose for the MQT is to provide an aggregation of data that cansatisfy many subsequent queries without repeating the full access to thedatabase.

Typically, the query table definition is in the form of a databasequery, herein referred to as a materialized query. The materializedquery is processed and the results are stored as the MQT. The resultscan be in the form of rows, which may be rows from a single base tableor rows created by joining rows in the base table. Materialized querytables eliminate the overhead associated with gathering and deriving thedata every time a query is executed. Through a process known as queryrewrite, a query can be optimized to recognize and use existingmaterialized query tables that could answer the query. Typically, thequery rewrite optimization is transparent to the application submittingthe query. That is, the rewrite operation happens automatically and doesnot require the application to know about the existence of materializedquery tables, nor that a particular materialized query table has beensubstituted in the original query.

Refreshing Materialized Query Tables

As new data is periodically added to the base tables corresponding to amaterialized query table, the materialized query table needs to beupdated to reflect the new base table data. When a materialized querytable accurately reflects all of the data currently in its base tables,the materialized query table is considered to be “fresh”. Otherwise, thematerialized query table is considered to be “stale”. A stalematerialized query table may be re-computed by various techniques thatare collectively referred to as a “refresh”.

The data in the MQT is either system maintained in real time or isdeferred until the user specifies to refresh the table. Deferring therefresh is sometimes referred to as deferred maintenance. Making thedecision whether to maintain the MQT in real time or in some deferredfashion is usually a business decision based upon available resourcesand the need for accurate data. In many systems, keeping MQT's up todate is not viable so different methods are used to initiate a manualrefresh of the data. In these prior art systems the refresh is undersoftware control by the user. Some prior art systems use different modesto tolerate data staleness. For example, software may access the MQT inan Enforced mode, and one or more modes that tolerate some amount ofdata staleness.

When software accesses the data in Enforced mode, the data is requiredto be 100% accurate. If the MQT is not up to date when accessed in thismode, the data must be retrieved from the base tables rather than fromthe MQT. Retrieving the data from the base tables is more costly insystem resources and in some cases may actually be more costly thanupdating the MQTs.

2.0 Detailed Description

The preferred embodiments herein provide an apparatus and method toautonomically refresh an MQT in a computer database. In preferredembodiments, the query optimizer autonomically initiates a refresh of anMQT depending on an estimated time for the query to access the basetables. In other preferred embodiments, the query optimizer estimatesthe time for the query to access the base tables and compares it to theestimated time to refresh the MQT to determine whether to refresh theMQT and run the query over the MQT rather than the base tables.

Referring now to FIG. 1, a computer system 100 is one suitableimplementation of an apparatus in accordance with the preferredembodiments of the invention. Computer system 100 is an IBM eServeriSeries computer system. However, those skilled in the art willappreciate that the mechanisms and apparatus of the present inventionapply equally to any computer system, regardless of whether the computersystem is a complicated multi-user computing apparatus, a single userworkstation, or an embedded control system. As shown in FIG. 1, computersystem 100 comprises a processor 110, a main memory 120, a mass storageinterface 130, a display interface 140, and a network interface 150.These system components are interconnected through the use of a systembus 160. Mass storage interface 130 is used to connect mass storagedevices (such as a direct access storage device 155) to computer system100. One specific type of direct access storage device 155 is a readableand writable CD RW drive, which may store data to and read data from aCD RW 195.

Main memory 120 in accordance with the preferred embodiments containsdata 122, an operating system 123, a database 124, one or more databasequeries 125, and a database query optimizer 126. Data 122 represents anydata that serves as input to or output from any program in computersystem 100. Operating system 123 is a multitasking operating systemknown in the industry as i5/OS; however, those skilled in the art willappreciate that the spirit and scope of the present invention is notlimited to any one operating system. Database 124 is any suitabledatabase, whether currently known or developed in the future. Database124 includes one or more base tables 127 as described further below.Database query 125 is a query in a format compatible with the database124 that allows information stored in the database 124 that satisfiesthe database query 125 to be retrieved. Database query optimizer 126optimizes a query 125 and produces an access plan used by a databasemanager in the database 124 to access the database. Database queryoptimizer 126 includes a Materialized Query Table (MQT) 128 that isautonomically updated by the query optimizer 126 in accordance with thepreferred embodiments. Database query optimizer 126 further includes astaging table 129 that is used by the query optimizer 126 in accordancewith the preferred embodiments. The staging table temporarily storesdata from queries that affect the MQT until the next update of the MQTis performed. The rows in the staging table are processed one at a timeand removed from the staging table as they are used to update the MQT.

Computer system 100 utilizes well known virtual addressing mechanismsthat allow the programs of computer system 100 to behave as if they onlyhave access to a large, single storage entity instead of access tomultiple, smaller storage entities such as main memory 120 and DASDdevice 155. Therefore, while data 122, operating system 123, database124, database query 125, and the database query optimizer 126 are shownto reside in main memory 120, those skilled in the art will recognizethat these items are not necessarily all completely contained in mainmemory 120 at the same time. It should also be noted that the term“memory” is used herein to generically refer to the entire virtualmemory of computer system 100, and may include the virtual memory ofother computer systems coupled to computer system 100.

Processor 110 may be constructed from one or more microprocessors and/orintegrated circuits. Processor 110 executes program instructions storedin main memory 120. Main memory 120 stores programs and data thatprocessor 110 may access. When computer system 100 starts up, processor110 initially executes the program instructions that make up operatingsystem 123. Operating system 123 is a sophisticated program that managesthe resources of computer system 100. Some of these resources areprocessor 110, main memory 120, mass storage interface 130, displayinterface 140, network interface 150, and system bus 160.

Although computer system 100 is shown to contain only a single processorand a single system bus, those skilled in the art will appreciate thatthe present invention may be practiced using a computer system that hasmultiple processors and/or multiple buses. In addition, the interfacesthat are used in the preferred embodiment each include separate, fullyprogrammed microprocessors that are used to off-load compute-intensiveprocessing from processor 110. However, those skilled in the art willappreciate that the present invention applies equally to computersystems that simply use I/O adapters to perform similar functions.

Display interface 140 is used to directly connect one or more displays165 to computer system 100. These displays 165, which may benon-intelligent (i.e., dumb) terminals or fully programmableworkstations, are used to allow system administrators and users tocommunicate with computer system 100. Note, however, that while displayinterface 140 is provided to support communication with one or moredisplays 165, computer system 100 does not necessarily require a display165, because all needed interaction with users and other processes mayoccur via network interface 150.

Network interface 150 is used to connect other computer systems and/orworkstations (e.g., 175 in FIG. 1) to computer system 100 across anetwork 170. The present invention applies equally no matter howcomputer system 100 may be connected to other computer systems and/orworkstations, regardless of whether the network connection 170 is madeusing present-day analog and/or digital techniques or via somenetworking mechanism of the future. In addition, many different networkprotocols can be used to implement a network. These protocols arespecialized computer programs that allow computers to communicate acrossnetwork 170. TCP/IP (Transmission Control Protocol/Internet Protocol) isan example of a suitable network protocol.

At this point, it is important to note that while the present inventionhas been and will continue to be described in the context of a fullyfunctional computer system, those skilled in the art will appreciatethat the present invention is capable of being distributed as a programproduct in a variety of forms, and that the present invention appliesequally regardless of the particular type of signal bearing media usedto actually carry out the distribution. Examples of suitable signalbearing media include: recordable type media such as floppy disks and CDRW (e.g., 195 of FIG. 1), and transmission type media such as digitaland analog communications links. Note that the preferred signal bearingmedia is tangible.

The preferred embodiments herein provide an apparatus and method toautonomically refresh an MQT in a computer database. In preferredembodiments, the query optimizer 126 autonomically initiates a refreshof an MQT 128 depending on an estimated time for the query to access thebase tables 127. In preferred embodiment, the query optimizer 126 parsesthrough pending queries that require non-stale data to find thosequeries that have a corresponding MQT 128. If the MQT is in deferredmaintenance then the query optimizer 126 proceeds to determine if it iseconomical to update the MQT prior to executing the query.

To determine if it's economical to update the MQT, the query optimizer126 first needs to estimate the time to update the MQT. In order toestimate the time to update the MQT, the query optimizer gets the queryassociated with the MQT and operates on them to estimate the run time ofthe computer to update the MQT. The estimation is done in the same wayas prior art techniques to estimate the time for a query. The estimationprocess is described further below. In some embodiments, the queryoptimizer also needs to retrieve the count of results in the stagingtable 129 and include this in making the time estimate to update theMQT. When MQT's are in a deferred mode, changes that would be made to anMQT because of changes in the base tables are put into a staging table.Therefore when the optimizer tries to estimate how much time will berequired to update the MQT, the time to run the queries against thestaging table will also need to be estimated.

To proceed to determine if its economical to update the MQT, the queryoptimizer 126 compares the estimated time to update the MQT with anestimate of the time to execute the query. If the update time is greaterthan the query execution time then the query optimizer 126 proceeds toupdate the MQT. Of course it would be obvious to those skilled in theart that other comparisons could also be made. For example the updatemay proceed if the MQT update time is some ratio of the execution time.

In the process to determine if its economical to update the MQT, thequery optimizer 126 may also estimate if the time to update the MQT isgreater than the time for processing the query including trigger events.A trigger event is a query that will spawn or may spawn other queries toexecute. In the case of a trigger event, the query optimizer 126 wouldalso consider the cumulative time in estimating the time to perform thequeries as compared to the time to update the MQT.

The process to estimate the time to update the MQT is performed similarto prior art techniques to estimate the time for running a query. Theestimation process according to preferred embodiments uses historicaldata from previous queries to more accurately estimate the time toupdate the MQT. FIG. 9 shows an example of a historical data record 900.A historical data record 900 is stored for queries corresponding to anMQT. The data that is stored in the historical record includes a copy ofthe query or an appropriate query identifier 910, a time stamp 920, thetime for the query to execute 930, the number of records affected by thequery 940, a trigger query status 950, and a trigger ID 960.

The time stamp 920 shown in FIG. 9 records when a query was executed bythe computer. The time stamp can be used as a means to identify if aquery is part of a sequence of queries associated with a trigger query.The historical data and the time stamp can be examined by the optimizerto identify queries that execute proximate to each other in time. Othermeans could also be used to identify a trigger query such as identifyingqueries that are called by the same application program.

Again referring to the historical data record fields in FIG. 9, when aquery is executed, the start time and stop time are noted to determinethe time to execute the query 930. The number of records affected 940 bythe query can also be used to estimate future update times. The “TriggerQuery?” field 950 holds a true or false value to indicate whether thequery has been identified as a trigger query. The trigger query ID 960holds a value to identify the query as being associated with a triggerquery. The trigger query ID 960 would be the same for all queries thatare associated with an identified trigger query. Thus, a trigger ID tiesa sequence of queries together into a block that can be used to estimatethe time to update the MQT.

Referring now to FIG. 5, a flow diagram shows a method 500 forautonomically refreshing an MQT according to a preferred embodiment. Themethod 500 is presented as a series of steps performed by a computersoftware program described above as a query optimizer 126. The queryoptimizer gets one or more queries that require non-stale data fromsoftware operating on the computer system (step 510). The queryoptimizer parses through pending queries to determine what tables arereferenced in the queries (step 520). For each table referenced in thequeries the query optimizer performs the following two steps todetermine whether there are MQT tables that are candidates to be updated(step 530). The query optimizer first checks to see if the table has acorresponding MQT (step 540). If there is no corresponding MQT for thistable (step 540=no) then the query optimizer proceeds to the next table.If there is a corresponding MQT for this table (step 540=yes) then thequery optimizer proceeds to the next step. The query optimizer thenchecks if the MQT for the current table is in deferred maintenance (step550). If the MQT is not in deferred maintenance (step 550=no), the MQTdoes not need to be updated and the query optimizer proceeds with thenext table (step 530). If the MQT is in deferred maintenance (step550=yes), the MQT is a candidate to be updated and the query optimizerproceeds to determine if it is economical to update the MQT (step 560and described further below with respect to method 560 in FIG. 6) priorto executing the query (step 570 and described further below withrespect to method 570 in FIG. 8).

Referring now to FIG. 6, a flow diagram shows a method 560 whichdescribes a representative method for step 560 in FIG. 5. Method 560 isa method to determine if it is economical to update the MQT according toa preferred embodiment. To determine if its economical to update theMQT, the query optimizer 126 first needs to estimate the time to updatethe MQT (step 610 and described further below with respect to method 610in FIG. 7). The estimated time to update the MQT is compared to theestimated query execution time that is also determined by the queryoptimizer (step 620). If the time to update the MQT is not greater thanthe time for execution of the query (step 620=no) then the MQT isupdated (step 630). If the time to update the MQT is greater than thetime for execution of the query (step 620=yes) the query historicalrecord is checked to determine if there is a trigger event associatedwith the query (step 640). In the case of a trigger event, the queryoptimizer 126 would also consider the cumulative time in estimating thetime to perform the queries as compared to the time to update the MQT.If there is no trigger event (step 640=no) then the method is done. Ifthere is a query event (step 640=yes) then the estimated time to updatethe MQT is compared to the estimated time to execute the query includingthe trigger events (step 650). If the estimated time to update the MQTis not greater than the estimated time to execute the query includingthe trigger events (step 650=no) then the MQT is updated (step 630) andthe method is then done. If the estimated time to update the MQT isgreater than the estimated time to execute the query including thetrigger events (step 650=yes) then the MQT is not updated and the methoddone.

Referring now to FIG. 7, a flow diagram shows a method 610 to estimatethe time to update the MQT according to a preferred embodiment, which isone suitable implementation of step 610 in FIG. 6. In order to estimatethe time to update the MQT, the query optimizer gets the queriesassociated with the MQT (step 710). The query optimizer then operates onthe queries to estimate the run time of the computer to update the MQT(step 720). The query optimizer where applicable also needs to retrievethe count of results in the staging table and include this in making thetime estimate to update the MQT (step 730). The query optimizer thenproduces an estimate of how much time is needed to update the MQT (step740).

Referring now to FIG. 8, a flow diagram shows a method 570 to create ahistorical record of the times to update the MQT according to apreferred embodiment which is one suitable implementation of step 570 inFIG. 5. The method first gets the start time (step 810), prior toexecuting the query (step 820). The query is executed in the mannerknown in the prior art. After completing the execution of the query, themethod then gets the stop time (step 830). The start time and stop timeare relative time marks that are typically available to the computerprocessor. The start time and stop time are then used to compute a time930 to execute the query, which is stored in the historical data record900 described above with reference to FIG. 9. The method also retrievesthe record count of records that are pending in the staging table (step840) for the executed query. The accumulated data is then stored in thehistorical data record (step 850).

The present invention as described with reference to the preferredembodiments provides significant improvements over the prior art. Anapparatus and method provide autonomic refresh of an MQT in a computerdatabase. The present invention provides a way to reduce database querytime to improve system performance, and reduce excessive delays indatabase accesses.

One skilled in the art will appreciate that many variations are possiblewithin the scope of the present invention. Thus, while the invention hasbeen particularly shown and described with reference to preferredembodiments thereof, it will be understood by those skilled in the artthat these and other changes in form and details may be made thereinwithout departing from the spirit and scope of the invention.

The invention claimed is:
 1. An apparatus comprising: at least oneprocessor; a memory coupled to the at least one processor; a databaseresiding in the memory having data; a query optimizer residing in thememory that parses a query to identify a base table of the database witha materialized query table (MQT) in deferred maintenance; and whereinthe query optimizer autonomically determines whether to update the MQTor execute the query over the base table by estimating a time to executethe query over the base table corresponding to the MQT, estimating atime to update the MQT, comparing the estimated time to update the MQTand the estimated time to execute the query over the base table; andwherein the query optimizer updates the MQT where the estimated time toupdate the MQT is less than the time to execute the query over the basetable; and executes the query over the updated MQT.
 2. The apparatus ofclaim 1 wherein the query optimizer considers a time of trigger eventsto estimate the time to refresh the MQT.
 3. The apparatus of claim 1wherein the query optimizer considers results stored in a staging tableto estimate the time to refresh the MQT.
 4. A program productcomprising: a query optimizer that parses a query to identify a basetable with a materialized query table (MQT), wherein the query optimizerautonomically determines whether to update the MQT or execute the queryover the base table by estimating a time to execute the query over thebase table corresponding to the MQT, estimating a time to update theMQT, comparing the estimated time to update the MQT and the estimatedtime to execute the query over the base table, wherein the queryoptimizer updates the MQT where the estimated time to update the MQT isless than the time to execute the query; and executes the query over theupdated MQT; and non-transitory computer-recordable media bearing thequery optimizer.
 5. The program product of claim 4 wherein the queryoptimizer considers a time of trigger events to estimate the time torefresh the MQT.
 6. The program product of claim 4 wherein the queryoptimizer considers results stored in a staging table to estimate thetime to refresh the MQT.
 7. An apparatus comprising: at least oneprocessor; a memory coupled to the at least one processor; a databaseresiding in the memory having data; a query optimizer residing in thememory that parses a query to identify a base table of the database witha materialized query table (MQT), meaning the refresh of the MQT hasbeen deferred; wherein the query optimizer autonomically determineswhether to update the MQT or execute the query over the base table byestimating a time to execute the query over the base table correspondingto the MQT, estimating a time to update the MQT, comparing the estimatedtime to update the MQT and the estimated time to execute the query overthe base table; wherein the query optimizer updates the MQT since theestimated time to update the MQT is less than the time to execute thequery over the base table; and executes the query over the updated MQT;wherein the query optimizer considers a time of trigger events toestimate the time to refresh the MQT; and wherein the query optimizerconsiders results stored in a staging table to estimate the time torefresh the MQT.